<!-- Created by mhy on 2018/7/11.

 -->
<template>
    <div class="e-select-area">
      <div class="box">
        <p class="box-title">{{defaultFc ? '修改' : '新增'}}关联厂家编号</p>
        <p class="close-btn" @click="close">X</p>
        <div class="select-content">
            <div class="num-content">
              <p style="margin-left: 20px;color: #303641;font-size: 14px">{{infotype}}编号</p>
              <input class="num-input" v-model="defText" id="inputseq" @input="inputed"  :placeholder="typeplc">
            </div>
          <m-select v-model="value" :options="options" title="选择厂家" class="m-mb-10" @change="changeSearch()"/>
          <p @click="submit" class="submit-btn">完成</p>
        </div>
      </div>
    </div>
</template>

<script>
    export default {
      name: 'e-select',
      data() {
            return {
                value: '0',
                typeplc: '',
                defText: '',
                options: this.$store.state.factory.factoryOptionsData
            }
      },
      props: {
        infotype: '',
        defaultText: '',
        defaultFc: ''
      },
      computed: {
//        typepl (){
//            return  '请输入' + this.infoType + '编号'
//        },
//        deftext: {
//            get: function () {
//              return this.defaultText
//            },
//            set: function (value) {
////              this.deftext = value
//            }
//        }
      },
      watch: {
        defaultFc (newValue){
          if (this.options.length){
            for(var i = 0;i < this.options.length; i ++){
              let sub = this.options[i]
              if(this.defaultFc == sub.factoryid){
                this.value = sub.value
              }
            }
          }
        },
        defaultText (newValue) {
            this.defText = newValue
        },
//        infoType (newValue) {
//          this.typeplc = '请输入' + this.infoType + '编号'
//        }
      },
      mounted (){
//          console.log(this.infoType)
        this.typeplc = '请输入' + this.infotype + '编号'
//        console.log('默认------------' + this.defaultText)
//        this.defText = this.defaultText
//        if (this.options.length){
//            for(var i = 0;i < this.options.length; i ++){
//              let sub = this.options[i]
//              if(this.defaultFc == sub.factoryid){
//                  this.value = sub.value
//              }
//            }
//        }
      },
      methods: {
        changeSearch (){

        },
        inputed(){

        },
        submit() {
          let value = document.getElementById('inputseq').value
          if (!value){
            this.$dialog.toast({
              mes: '请先填写编号',
              timeout: 1000
            })
            return
          }
          if (this.value == '0'){
            this.$dialog.toast({
              mes: '请先选择厂家',
              timeout: 1000
            })
            return
          }
          this.$emit('submit-factory',value,String(Number(this.value) - 1))
        },
        close(){
          this.$emit('close-factory', true)
        }
      }
    }
</script>

<style scoped>

  p{
    font-size: 16px;
    color: #303641;
  }
  .submit-btn{
    background-color: #39B866;
    width: 690px;
    height: 50px;
    color: white;
    line-height: 50px;
    margin-top: 30px;
    border-radius: 6px;
  }
  .m-mb-10{
    width:690px;
    height: 50px;
    margin-top: 30px;

  }
  .num-input{
    width: 300px;
    text-align: right;
    height: 48px;
    border: none;
    padding-right: 20px;
    margin-right: 3px;
  }
  .num-content{
    width: 690px;
    height:50px;
    /*margin-left: 30px;*/
    margin-top: 30px;
    display: flex;
    display: -webkit-flex;
    align-items: center;
    background-color: white;
    justify-content: space-between;
    border: 0.1px solid #C8C7CC;
  }
  .box-title{
    margin-top:30px
  }
  .select-content{
    position: absolute;
    top: 78px;
    width: 100%;
    height: 290px;
    background-color: #F2F2F2;
    display: flex;
    display: -webkit-flex;
    flex-direction: column;
    align-items: center;
  }
  .close-btn{
    position: absolute;
    right: 20px;
    top:30px;
  }
  .box{
    width: 750px;
    height: 370px;
    background-color: white;
    top: 150px;
    position: absolute;
    left: 250px;
    right: 0;
    /*position: relative;*/
  }
  .e-select-area{
    width: 100%;
    height:100%;
    position: absolute;
    top: 0;
    /*background-color: #02bb00;*/
    background-color: rgba(0,0,0,0.3);
  }
</style>
